package com.briup.corejava.day18;

import java.io.*;

/**
 * 转换流的测试
 * InputStreamReader
 * OutputStreamWriter
 * 将字节流转换成字符流的时候可以指定编码，默认编码为utf-8
 */
public class Test5 {
    public static void main(String[] args) {
        FileInputStream fis = null;
        InputStreamReader isr = null;
        BufferedReader br = null;

        FileOutputStream fos = null;
        OutputStreamWriter osr = null;
        PrintWriter pw = null;

        try {
            fis = new FileInputStream("src/com/briup/corejava/day18/file/gbk.txt");
            // 使用gbk编码读取 -> 解码
            isr = new InputStreamReader(fis,"gbk");
            br = new BufferedReader(isr);

            fos = new FileOutputStream("src/com/briup/corejava/day18/file/gbk_copy.txt");
            // 使用utf-8写出 -> 编码
            osr = new OutputStreamWriter(fos);
            pw = new PrintWriter(osr);

            String line = null;
            while((line=br.readLine())!=null){
                pw.println(line);
                pw.flush();
            }
            System.out.println("数据写出完毕，默认编码为utf8");

        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {

        }
    }
}
